#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../h/scheme.h"
#include "../h/symtab.h"

int tests(){

	SchemeObject ** environment[10];
	SchemeObject *vector[2];
	char *s = (char *)malloc((sizeof(char))*5);
	strcpy(s, "hello");
	SOBVoid testVoid		= {SCHEME_VOID};
	SOBNil testNil			= {SCHEME_NIL};
	SOBInt 	testInt 		= {SCHEME_INT,5};
	SOBChar testChar 		= {SCHEME_CHAR, 'c'};
	SOBBool testBool		= {SCHEME_BOOL, 1};
	SOBString testString 	= {SCHEME_STRING, 5, s};
	SOBPair	testPair		= {SCHEME_PAIR, SOB(&testInt), SOB(&testChar)};
	SymbolEntry se = {"sym", 1, SOB(&testPair)};
	vector[0]=SOB(&testBool);
	vector[1]=SOB(&testString);
	SOBVector testVector	= {SCHEME_VECTOR, 2, vector};
	SOBSymbol testSymbol	= {SCHEME_SYMBOL, &se};

	printf("void");
	printf("\ntype: %d value:", IS_SOB_VOID(&testVoid));

	printf("\nnil");
	printf("\ntype: %d value:", IS_SOB_NIL(&testNil));

	printf("\nint");
	printf("\ntype: %d value: %d", IS_SOB_INT(&testInt) ,SOB_INT_VALUE(&testInt));

	printf("\nchar");
	printf("\ntype: %d value: %d", IS_SOB_CHAR(&testChar) ,SOB_CHAR_VALUE(&testChar));

	printf("\nbool");
	printf("\ntype: %d value: %d", IS_SOB_BOOL(&testBool) ,SOB_BOOL_VALUE(&testBool));

	printf("\nstring");
	printf("\ntype: %d length: %d value: %s", IS_SOB_STRING(&testString),
											SOB_STRING_LENGTH(&testString),
											SOB_STRING_VALUE(&testString));
	printf("\nstring's 3rd char: %c",SOB_STRING_REF(&testString, 3));
	printf("\nstring's 4th char: %c",SOB_STRING_REF(&testString, 4));
	printf("\nsetting 3rd char of string to A...");
	SOB_STRING_SET(&testString, 3, 'A');
	printf("\nstring's 3rd char: %c",SOB_STRING_REF(&testString, 3));

	printf("\npair");
	printf("\ntype: %d", IS_SOB_PAIR(&testPair));
	if (SOB_PAIR_CAR(&testPair)== SOB(&testInt))
		printf("\ncar:OK");
	if (SOB_PAIR_CDR(&testPair)== SOB(&testChar))
		printf("\ncdr:OK");

	//SOB_CHAR_VALUE(x)			SOB_CHR((x))->value
	//SOB_BOOL_VALUE(x)			SOB_BOO((x))->value
	//SOB_STRING_LENGTH(x)		SOB_STR((x))->length
	//SOB_STRING_VALUE(x)			SOB_STR((x))->value
	//SOB_STRING_REF(x, i)		SOB_STRING_VALUE((x))[i]
	//SOB_STRING_SET(x, i, sob)	SOB_STRING_VALUE((x))[i] = sob
	//SOB_PAIR_CAR(x)				SOB_PAR((x))->car
	//SOB_PAIR_CDR(x)				SOB_PAR((x))->cdr
	//SOB_VECTOR_VALUE(x)			SOB_VEC((x))->vec
	//SOB_VECTOR_LENGTH(x, n)		SOB_VEC((x))->length
	//SOB_VECTOR_REF(x, i)		SOB_VECTOR_VALUE((x))[i]
	//SOB_VECTOR_SET(x, i, sob)	SOB_VECTOR_VALUE((x))[i] = sob
	//SOB_SYMBOL_ENTRY(x)			SOB_SYM((x))->sep
	//SOB_CLOSURE_ENV(x)			SOB_CLS((x))->env
	//SOB_CLOSURE_CODE(x)			SOB_CLS((x))->code

	SOBClosure testClosure	= {SCHEME_CLOSURE, &environment, &&CODE};

	CODE:
		printf ("\n%s","hello world!");

    return 0;
}
